<?php
require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/bootstrap/database.php';
require_once __DIR__.'/bootstrap/services.php';
require_once __DIR__.'/bootstrap/arguments.php';

use App\Services\CollegeSpiderService;
use Workerman\Worker;
use App\Workers\CollegeSpiderWorker;

// 解析命令行参数
$args = parseArguments($argv);
$options = $args['options'];
$batchSize = $args['batchSize'];
$limit = $args['limit'];
$startTime = $args['startTime'];

// 创建Worker
$worker = new Worker('http://0.0.0.0:2345');
$worker->name = 'CollegeSpider';
$worker->count = 1;
$worker->reloadable = true;
$worker->user = '';
$worker->stdoutFile = '/tmp/college-spider.stdout.log';
$worker->pidFile = '/tmp/college-spider.pid';
$worker->logFile = '/tmp/college-spider.log';

// 初始化爬虫服务
$proxy_enable = isset($options['proxy_enable']);
$collegeSpiderService = new CollegeSpiderService($proxy_enable);

// 设置Worker业务逻辑
CollegeSpiderWorker::run($worker, $collegeSpiderService, $batchSize, $limit, $options);

// 运行worker
Worker::runAll();
